﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DotNet.WinUI.Basic
{
    public partial class FrmListControl : Form
    {
        public FrmListControl()
        {
            InitializeComponent();
        }

        private void cmbProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbCity.Items.Clear();
            cmbCounty.Items.Clear();

            string[] _str = null;
            if (cmbProvince.Text == "云南省")
            {
                _str = new string[] { "昆明市", "大理州", "红河州", "曲靖市", "丽江地区" };
            }
            else if (cmbProvince.Text == "四川省")
            {
                _str = new string[] { "成都市", "雅安市", "自贡市", "乐山市" };
            }
            else if (cmbProvince.Text == "重庆市")
            {
                _str = new string[] { "渝中区", "九龙坡", "江北" };
            }
            else if (cmbProvince.Text == "北京市")
            {
                _str = new string[] { "朝阳", "密云" };
            }
            else
            {
                _str = new string[] { "未州市" };
            }
            cmbCity.Items.AddRange(_str);
            cmbCity.SelectedIndex = 0;
        }

        private void cmbCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbCounty.Items.Clear();

            string[] _str = null;
            if (cmbCity.Text == "昆明市")
            {
                _str = new string[] { "五华区", "嵩明县", "呈贡区", "安宁市", "晋宁县" };
            }
            else if (cmbCity.Text == "大理州")
            {
                _str = new string[] { "下关", "祥云", "巍山" };
            }
            else if (cmbCity.Text == "红河州")
            {
                _str = new string[] { "蒙自", "个旧", "开远", "河口" };
            }
            else
            {
                _str = new string[] { "未添加县" };
            }
            cmbCounty.Items.AddRange(_str);
            cmbCounty.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] _Region = new string[] { "五华区", "盘龙区", "西山区", "官渡区", "安宁县", "嵩明县", "石林县", "呈贡县", "宜良县" };
            cmbRegion.DataSource = _Region;
        }

        private void cheSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            if (cheSelectAll.Checked)
            {
                for (int j = 0; j < chkInterest.Items.Count; j++)
                {
                    chkInterest.SetItemChecked(j, true);
                }
            }
            else
            {
                for (int j = 0; j < chkInterest.Items.Count; j++)
                {
                    chkInterest.SetItemChecked(j, false);
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            txtResult.Clear();
            for (int i = 0; i <= chkInterest.Items.Count - 1; i++)
            {
                if (chkInterest.GetItemChecked(i))
                {
                    txtResult.Text += chkInterest.GetItemText(chkInterest.Items[i]) + "\n";
                }
            }
        }

        private void cmbModule_SelectedIndexChanged(object sender, EventArgs e)
        {
            lstFun.Items.Clear();
            lstSelected.Items.Clear();

            string[] _str = null;
            if (cmbModule.Text == "系统管理")
            {
                _str = new string[] { "用户管理", "角色管理", "修改密码", "备份数据", "恢复数据", "操作日志" };
            }
            else if (cmbModule.Text == "基本信息")
            {
                _str = new string[] { "车型管理", "厂家管理", "排量管理", "颜色管理", "载重管理" };
            }
            else if (cmbModule.Text == "车辆管理")
            {
                _str = new string[] { "IC卡信息", "驾驶员管理", "车辆信息" };
            }
            lstFun.Items.AddRange(_str);
        }

        private void btnAll_Click(object sender, EventArgs e)
        {
            for (int i = lstFun.Items.Count - 1; i >= 0; i--)
            {
                lstSelected.Items.Add(lstFun.Items[i]);
                lstFun.Items.Remove(lstFun.Items[i]);
            }
        }

        private void btnSelected_Click(object sender, EventArgs e)
        {
            for (int i = lstFun.Items.Count - 1; i >= 0; i--)
            {
                if (lstFun.GetSelected(i))
                {
                    lstSelected.Items.Add(lstFun.Items[i]);
                    lstFun.Items.Remove(lstFun.Items[i]);
                }
            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            for (int i = lstSelected.Items.Count - 1; i >= 0; i--)
            {
                if (lstSelected.GetSelected(i))
                {
                    lstFun.Items.Add(lstSelected.Items[i]);
                    lstSelected.Items.Remove(lstSelected.Items[i]);
                }
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            for (int i = lstSelected.Items.Count - 1; i >= 0; i--)
            {
                lstFun.Items.Add(lstSelected.Items[i]);

                lstSelected.Items.Remove(lstSelected.Items[i]);
            }
        }

        private void lstFun_DoubleClick(object sender, EventArgs e)
        {
            if (lstFun.SelectedIndex >= 0)
            {
                lstSelected.Items.Add(lstFun.SelectedItem);
                lstFun.Items.Remove(lstFun.SelectedItem);
            }
        }

        private void lstSelected_DoubleClick(object sender, EventArgs e)
        {
            if (lstSelected.SelectedIndex >= 0)
            {
                lstFun.Items.Add(lstSelected.SelectedItem);
                lstSelected.Items.Remove(lstSelected.SelectedItem);
            }
        }
    }
}
